# 442 中等：数组中重复的数据

def findDuplicates(nums):
    nums = sorted(nums)
    ret = []
    for i in range(len(nums) - 1):
        if nums[i] == nums[i + 1]:
            ret.append(nums[i])

    return ret


print(findDuplicates([4,3,2,7,8,2,3,1]))

# class Solution:
#     def findDuplicates(self, nums: List[int]) -> List[int]:
#         for i in range(len(nums)):
#             while nums[i] != nums[nums[i] - 1]:
#                 nums[nums[i] - 1], nums[i] = nums[i], nums[nums[i] - 1]
#         return [num for i, num in enumerate(nums) if num - 1 != i]
#
#
# class Solution:
#     def findDuplicates(self, nums: List[int]) -> List[int]:
#         ans = []
#         for x in nums:
#             x = abs(x)
#             if nums[x - 1] > 0:
#                 nums[x - 1] = -nums[x - 1]
#             else:
#                 ans.append(x)
#         return ans

